import MathUtil from '@/MathUtil';
import RandomUtil from '@/RandomUtil';
import SummonCommon from 'code/Core/Common/SummonCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 火蛇图腾
 **/
export default class SM_FireSnakeToten extends AbilityBase {
    static instance: SM_FireSnakeToten;
    constructor(id: string = 'Ahst') {
        super(id);
        SM_FireSnakeToten.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
        EventManager.onTakeAttack(this.onAttackEffect.bind(this));
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let lv = this.getAbilityLevel(source);
        let count = R2I(lv / 2) + 1;
        let fp = UnitCommon.getFullProperty(source);
        let attack = 15 + (fp * lv) / 7;
        let life = 150 * lv + (fp * lv) / 5;
        let armor = 10 + (fp * lv) / 15;
        let int = UnitCommon.取总智力(source) + UnitCommon.取总精神(source);
        SummonCommon.summon({
            abilityId: this.id,
            unitTypeId: 'osp1',
            caster: source,
            x: tarX,
            y: tarY,
            lifeTime: 35 + 20 * lv,
            attr: {
                attack,
                life,
                附加护甲: armor,
                附加魔抗: armor,
            },
            count,
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    // 火蛇攻击转换为火焰伤害
    onAttackEffect(d: DamageEventData) {
        if (GetUnitAbilityLevel(d.source, 'Vhsf') == 0) return;
        let dmg = d.lastDamage;
        d.lastDamage = 0;
        DamageSystemInstance.applyFireDamage(d.target, d.source, dmg, this.id);
    }
}
